<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/15
 * Time: 14:26
 */
$serv = new swoole_server('127.0.0.1', 9502, SWOOLE_PROCESS, SWOOLE_SOCK_UDP);

$serv->set([
    'worker_num' => 4,//worker进程数
    'max_request' => 10000,
]);

//监听数据接收事件
$serv->on('Packet', function ($serv, $data, $client_info) {
    $fd = unpack('L', pack('N', ip2long($client_info['address'])))[1];
    $reactor_id = ($client_info['server_socket'] << 16) + $client_info['port'];

    $serv->sendto($client_info['address'], $client_info['port'], "Server: 线程id：{$reactor_id}，客户端id：{$fd}，接收数据：".$data);

    print_r($client_info);
    echo "客户端端口：{$client_info['port']} 发过来的数据是：" . $data;
});

//启动服务器
$serv->start();